package Proc::RPC::Result;

require 5.003;
use Moose;

has 'stdout' => (
  is => 'rw',
  isa => 'Str',
  default => '',
);

has 'stderr' => (
  is => 'rw',
  isa => 'Str',
  default => '',
);

has 'status' => (
  is => 'rw',
  isa => 'Int',
  default => 0,
);

has 'result' => (
  is => 'rw',
  isa => 'Ref',
);

use overload q{""} => \&_toString,
             bool  => \&_toBool,
             '0+' => \&_toNumber,
             fallback => 1;

sub _toBool {
  my $self = shift;

  !$self->status;
}

sub _toString {
  my $self = shift;

  $self->stderr . '|' . $self->stdout;
}

sub _toNumber {
  my $self = shift;

  (shift @{$self->result()}) + 0;
}


1;
__END__

=head1 NAME

Proc::RPC::Result - Object container of a rpc call.

=head1 SYNOPSIS

  use Proc::RPC;

  my $stdout_test = "Standard Output capture test";
  my $p = Proc::RPC->new();
  $p->rpc(sub { print $stdout_test });
  my $ret = $p->join();
  is($ret->stdout(), $stdout_test, $stdout_test);

  my $stderr_test = "Standard Error capture test";
  my $p = Proc::RPC->new();
  $p->rpc(sub { print STDERR $stderr_test });
  my $ret = $p->join();
  is($ret->stderr(), $stderr_test, $stderr_test);

  my $p = Proc::RPC->new();
  $p->rpc(sub { exit 1 });
  my $ret = $p->join();
  is($ret->status(), 256, "Status Code capture test");

=head1 AUTHOR

Pablo Chinea E<lt>alu2592@etsii.ull.esE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2011 by Pablo

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.10.0 or,
at your option, any later version of Perl 5 you may have available.

